-- @owner: lvlintao
-- @date: 2025-11-18
-- @testpoint: D兼容性-创建触发器，不加表名删除触发器，成功
@connect PrimaryDbDmode;
--step1 建表;expect:成功
drop table if exists case0001;
drop table if exists case0002;
create table case0001(id int, name char(30));
create table case0002(id int, foodtype varchar(32), remark varchar(32), time_flag timestamp);
--step2 创建函数，触发器;expect:成功
create or replace function insert_fun1 returns trigger as
$d$
begin
   insert into case0002 (id, foodtype, remark, time_flag) values(1, 'cake','healthy', now());
   return new;
end;
$d$ language plpgsql;
/
create trigger test_trigger1 after insert on case0001
for each row
execute procedure insert_fun1();/
create or replace function insert_fun2 returns trigger as
$d$
begin
   insert into case0002 (id, foodtype, remark, time_flag) values(1, 'humberger', 'healthy', now());
   return new;
end;
$d$ language plpgsql;
/
create trigger test_trigger2 after insert on case0001
for each row
execute procedure insert_fun2();/
--step3 查看触发器定义，测试触发器功能;expect:成功
select tgname from pg_trigger;
select count(*) from case0002;
insert into case0001(id, name) values(1, 'child');
select * from case0001;
select count(*) from case0002;
--step4 删除触发器;expect:成功
delete from case0001;
delete from case0002;
drop trigger test_trigger1 cascade;
drop trigger if exists test_trigger2;
select tgname from pg_trigger;
drop function if exists insert_fun1;
drop function if exists insert_fun2;
drop table if exists case0001;
drop table if exists case0002;
